<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>

  <script src="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-M/vue/2.6.14/vue.js"
    type="application/javascript"></script>
</head>

<body>
  <div id="app">
    {{username}}
    <no-use-slot @username="handleUsername"></no-use-slot>
    <use-slot>
      <template v-slot="{location}">
        {{location}}
      </template>
    </use-slot>
  </div>
</body>
<script>
  Vue.component('no-use-slot', {
    template: `
      <div>不用作用域插槽的子组件-</div>
    `,
    data () {
      return {
        username: 'fanfan',
      }
    },
    mounted () {
      this.$emit('username', this.username)
    }
  })
  Vue.component('use-slot', {
    template: `
      <div>用作用域插槽的子组件-<slot :location="location"></slot></div>
    `,
    data () {
      return {
        location: 'chongqing',
      }
    },
  })
  new Vue({
    el: '#app',
    data () {
      return {
        username: ''

      }
    },
    created () { },
    mounted () {
    },
    methods: {
      handleUsername (val) {
        this.username = val
      }
    },
  })
</script>

</html>